package mn.idax.exchange.otc.task;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob;
import mn.idax.exchange.otc.domain.FrozenUserAdDTO;
import mn.idax.exchange.otc.enums.AdEnum;
import mn.idax.exchange.otc.service.OTCAdsService;
import mn.idax.exchange.otc.util.DateUtils;
import mn.idax.exchange.otc.util.LogUtils;
import mn.idax.exchange.otc.vo.OTCAutoDownAdDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @Author: jack_huang
 * @Date: 2019/7/31 11:45
 * 用户在场内被冻结，无法登陆 亦无法操作otc数据，帮其下架广告
 */
@ElasticSimpleJob(cron="0 0/1 * * * ?")
@Component
public class FrozenUserDownAdJob implements SimpleJob {

    @Autowired
    private OTCAdsService otcAdsService;
    @Override
    public void execute(ShardingContext shardingContext) {
        List<FrozenUserAdDTO> frozenUserPublishAds = otcAdsService.getFrozenUserPublishAds();
        if (!frozenUserPublishAds.isEmpty()){
            Date currDate = DateUtils.getUTCNow();
            //下架广告
            for (FrozenUserAdDTO frozenUserPublishAd : frozenUserPublishAds) {
                OTCAutoDownAdDTO otcAutoDownAdDTO = new OTCAutoDownAdDTO();
                otcAutoDownAdDTO.setUpdateTime(currDate);
                otcAutoDownAdDTO.setState(AdEnum.state_down.getCode());
                otcAutoDownAdDTO.setId(frozenUserPublishAd.getId());
                otcAdsService.updateStateOTCAdsById(otcAutoDownAdDTO);

                LogUtils.info(this.getClass(), "AdvertisingDownFrozenUserAd adId : " + frozenUserPublishAd.getId() + "userId: " + frozenUserPublishAd.getPublisherId());
                //产品确认不发通知
            }

        }
    }
}
